
#include "ipfe_for_HiDe.h"

// [*] CFeatureFactory_HiDe

CFeatureFactory_HiDe::CParameters CFeatureFactory_HiDe::Parameters;

CImageFilterBank* CFeatureFactory_HiDe::GenerateFilterBank()
{
	int i;

	CImageFilterBank* ret = new CImageFilterBank();
	ret->myInit();

	CImageFilter_RGB* pFilter_RGB = ret->pBasicFilter_RGB;

	CImageFilter_Gray* pFilter_Gray = new CImageFilter_Gray();
	pFilter_Gray->PushBackInputResponse(pFilter_RGB, 0);
	pFilter_Gray->PushBackInputResponse(pFilter_RGB, 1);
	pFilter_Gray->PushBackInputResponse(pFilter_RGB, 2);
	ret->PushBackFilter(pFilter_Gray);

	CImageFilter_Lab* pFilter_Lab = new CImageFilter_Lab();
	pFilter_Lab->PushBackInputResponse(pFilter_RGB, 0);
	pFilter_Lab->PushBackInputResponse(pFilter_RGB, 1);
	pFilter_Lab->PushBackInputResponse(pFilter_RGB, 2);
	ret->PushBackFilter(pFilter_Lab);

	CImageFilter_Gaussian* pFilter_Gaussian = new CImageFilter_Gaussian(Parameters.TextonSigma * 1.0);
	pFilter_Gaussian->PushBackInputResponse(pFilter_RGB, 0);
	pFilter_Gaussian->PushBackInputResponse(pFilter_RGB, 1);
	pFilter_Gaussian->PushBackInputResponse(pFilter_RGB, 2);
	pFilter_Gaussian->PushBackInputResponse(pFilter_Gray, 0);
	pFilter_Gaussian->PushBackInputResponse(pFilter_Lab, 0);
	pFilter_Gaussian->PushBackInputResponse(pFilter_Lab, 1);
	pFilter_Gaussian->PushBackInputResponse(pFilter_Lab, 2);
	ret->PushBackFilter(pFilter_Gaussian);

	CImageFilter_LoG* pFilter_LoG = new CImageFilter_LoG(Parameters.TextonSigma * 1.0);
	pFilter_LoG->PushBackInputResponse(pFilter_Lab, 0);
	ret->PushBackFilter(pFilter_LoG);

	CImageFilter_1DoG* pFilter_1DoG_X = new CImageFilter_1DoG(true, Parameters.TextonSigma * 2.0);
	pFilter_1DoG_X->PushBackInputResponse(pFilter_Lab, 0);
	ret->PushBackFilter(pFilter_1DoG_X);

	CImageFilter_1DoG* pFilter_1DoG_Y = new CImageFilter_1DoG(false, Parameters.TextonSigma * 2.0);
	pFilter_1DoG_Y->PushBackInputResponse(pFilter_Lab, 0);
	ret->PushBackFilter(pFilter_1DoG_Y);

	CImageFilter_DooG* pFilter_DooG[6];
	for ( i = 0; i < 6; ++i )
	{
		pFilter_DooG[i] = new CImageFilter_DooG(1.0, i*PI/6, 3.0);
		pFilter_DooG[i]->PushBackInputResponse(pFilter_Lab, 0);
		ret->PushBackFilter(pFilter_DooG[i]);
	}

	CImageFilter_DoG* pFilter_DoG = new CImageFilter_DoG(1.0);
	pFilter_DoG->PushBackInputResponse(pFilter_Lab, 0);
	ret->PushBackFilter(pFilter_DoG);

	// Setting Response Output

	pFilter_RGB->PushBackOutput(0);			// R
	pFilter_RGB->PushBackOutput(1);			// G
	pFilter_RGB->PushBackOutput(2);			// B
	pFilter_Gray->PushBackOutput(0);		// Gray
	//pFilter_Gaussian->PushBackOutput(0);	// Gaussian(R)
	//pFilter_Gaussian->PushBackOutput(1);	// Gaussian(G)
	//pFilter_Gaussian->PushBackOutput(2);	// Gaussian(B)
	//pFilter_Gaussian->PushBackOutput(3);	// Gaussian(Gray)
	pFilter_Gaussian->PushBackOutput(4);	// Gaussian(L)
	pFilter_Gaussian->PushBackOutput(5);	// Gaussian(a)
	pFilter_Gaussian->PushBackOutput(6);	// Gaussian(b)
	pFilter_LoG->PushBackOutput(0);			// LoG(L)
	pFilter_1DoG_X->PushBackOutput(0);		// 1DoG_X(L)
	pFilter_1DoG_Y->PushBackOutput(0);		// 1DoG_Y(L)
	for ( i = 0; i < 6; ++i )
		pFilter_DooG[i]->PushBackOutput(0);	// DooG(L, i*PI/6)
	pFilter_DoG->PushBackOutput(0);		// DoG(L)

	// Finish Filter Bank Initialization

	ret->GetOutputDimension(true);

	return ret;
}

CImagePositionFeatureExtractor* CFeatureFactory_HiDe::GenerateIPFE(CImageFilterBank* pFixedImageFilterBank)
{
#if 1
	int i;
	C_IPFC_ImageFilterBankOwner* pIFBO = new C_IPFC_ImageFilterBankOwner(pFixedImageFilterBank->myClone(), Parameters.ImageExtent, false);
	for ( i = 0; i < pFixedImageFilterBank->GetOutputDimension(); ++i )
		pIFBO->PushBackResponseUser(new C_IPFC_ResponseUser_MeanAndVairance(&Parameters.ShapePatternList), &i);

	CCompositeIPFC* pCompositeIPFC = new CCompositeIPFC();
	pCompositeIPFC->PushBack(pIFBO);
#else
	int i, ii;
	CSimpleTypeArray<int> InputResponseList;
	InputResponseList.Clear();
	ii = pFixedImageFilterBank->GetOutputDimension();
	for ( i = 0; i < ii; ++i )
		InputResponseList.PushBack(i);

	CCompositeIPFC* pCompositeIPFC = new CCompositeIPFC();

	pCompositeIPFC->PushBack(
		new CResponseMeanAndVarianceIPFC(
		pFixedImageFilterBank, Parameters.ImageExtent, InputResponseList, &Parameters.ShapePatternList
		)
		);
#endif

	CImagePositionFeatureExtractor* ret = new CBasicIPFE(pCompositeIPFC);

	return ret;
}

CImagePyramidPositionFeatureExtractor* CFeatureFactory_HiDe::GenerateIPPFE(CImageFilterBank* pFixedImageFilterBank, int CacheSize)
{
	CImagePositionFeatureExtractor* pt = GenerateIPFE(pFixedImageFilterBank);
	CImagePyramidPositionFeatureExtractor* ret = new CImagePyramidPositionFeatureExtractor(pt, CacheSize);
	return ret;
}

//void CFeatureFactory_HiDe::InitSettings()
//{
//	CRectBox<int> tbox;
//	tbox.x = tbox.y = 0; tbox.w = tbox.h = 1;
//
//	Parameters.ShapePatternList.Clear();
//	Parameters.ShapePatternList.PushBack_SingleWindow(tbox, 1.0);
//	Parameters.ShapePatternList.PushBack_PatternFinishSign();
//}

//CImagePositionFeatureExtractor* CFeatureFactory_HiDe::GenerateIPFE()
//{
//	int i;
//	_C_ImageFilter* pImageFilter;
//
//	CSimpleTypeArray<_C_ImageFilter*> ImageFilterPtrList;
//	ImageFilterPtrList.Clear();
//
//#if USE_NEW_FEATURE
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(1));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(2));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gray());
//
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(3, Parameters.TextonSigma * 1.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(4, Parameters.TextonSigma * 1.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(5, Parameters.TextonSigma * 1.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, Parameters.TextonSigma * 1.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, Parameters.TextonSigma * 2.0, true));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, Parameters.TextonSigma * 2.0, false));
//
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 0.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 1.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 2.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 3.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 4.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 5.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 1.0));
//
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(3, Parameters.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(4, Parameters.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(5, Parameters.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(3, Parameters.TextonSigma * 4.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(4, Parameters.TextonSigma * 4.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(5, Parameters.TextonSigma * 4.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, Parameters.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, Parameters.TextonSigma * 4.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, Parameters.TextonSigma * 8.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, Parameters.TextonSigma * 4.0, true));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, Parameters.TextonSigma * 4.0, false));
//
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 0.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 1.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 2.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 3.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 4.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 5.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 1.5));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 4.0));
//
//#else
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gray());
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gradient(
//		_C_ImageFilter_Gradient::SOURCE_MODE_RGB, _C_ImageFilter_Gradient::PRE_MODE_NORMAL, 15, 1.0, false));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gradient(
//		_C_ImageFilter_Gradient::SOURCE_MODE_RGB, _C_ImageFilter_Gradient::PRE_MODE_NORMAL, 15, 2.0, false));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gradient(
//		_C_ImageFilter_Gradient::SOURCE_MODE_RGB, _C_ImageFilter_Gradient::PRE_MODE_NORMAL, 15, 4.0, false));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gradient(
//		_C_ImageFilter_Gradient::SOURCE_MODE_RGB, _C_ImageFilter_Gradient::PRE_MODE_NORMAL, 15, 8.0, false));
//#endif
//
//	CCompositeIPFC* pCompositeIPFC = new CCompositeIPFC();
//
//	for ( i = 0; i < (int)ImageFilterPtrList.Size; ++i )
//	{
//		pImageFilter = ImageFilterPtrList.pElement[i];
//		ImageFilterPtrList.pElement[i] = NULL;
//
//#if USE_NEW_FEATURE
//		pCompositeIPFC->PushBack(
//			new CResponseMeanAndVarianceIPFC(
//				pImageFilter->myClone(), &Parameters.ShapePatternList
//				)
//			);
//#else
//		pCompositeIPFC->PushBack(
//			new CResponseMeanIPFC(
//				pImageFilter->myClone(), &Parameters.ShapePatternList
//				)
//			);
//#endif
//
//		delete pImageFilter;
//		pImageFilter = NULL;
//	}
//
//	CImagePositionFeatureExtractor* ret = new CBasicIPFE(pCompositeIPFC, Parameters.ImageExtent);
//
//	return ret;
//}

/////////////////////////////////////////////////////////////////////

//// [*] C_IPPFE_Factory_HiDe
//
//C_IPPFE_Factory_HiDe::CParameters C_IPPFE_Factory_HiDe::IPFE_Config;
//
//CImagePositionFeatureExtractor* C_IPPFE_Factory_HiDe::GenerateIPFE()
//{
//	int i;
//	_C_ImageFilter* pImageFilter;
//
//	CSimpleTypeArray<_C_ImageFilter*> ImageFilterPtrList;
//	ImageFilterPtrList.Clear();
//
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(1));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(2));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_ColorChannel(3));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(3, IPFE_Config.TextonSigma * 1.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(3, IPFE_Config.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(3, IPFE_Config.TextonSigma * 4.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(4, IPFE_Config.TextonSigma * 1.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(4, IPFE_Config.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(4, IPFE_Config.TextonSigma * 4.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(5, IPFE_Config.TextonSigma * 1.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(5, IPFE_Config.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_Gaussian(5, IPFE_Config.TextonSigma * 4.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, IPFE_Config.TextonSigma * 1.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, IPFE_Config.TextonSigma * 2.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, IPFE_Config.TextonSigma * 4.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_LoG(3, IPFE_Config.TextonSigma * 8.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, IPFE_Config.TextonSigma * 2.0, true));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, IPFE_Config.TextonSigma * 4.0, true));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, IPFE_Config.TextonSigma * 2.0, false));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_1DoG(3, IPFE_Config.TextonSigma * 4.0, false));
//
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 0.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 1.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 2.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 3.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 4.0*PI/6, 3.0));
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.0, 5.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 0.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 1.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 2.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 3.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 4.0*PI/6, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DooG(3, 1.8, 5.0*PI/6, 3.0));
//
//	ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 1.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 1.5));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 3.0));
//	//ImageFilterPtrList.PushBack(new _C_ImageFilter_DoG(3, 4.0));
//
//	CCompositeIPFC* pCompositeIPFC = new CCompositeIPFC();
//
//	for ( i = 0; i < ImageFilterPtrList.Size; ++i )
//	{
//		pImageFilter = ImageFilterPtrList.pElement[i];
//		ImageFilterPtrList.pElement[i] = NULL;
//
//		pCompositeIPFC->PushBack(
//			new CResponseMeanAndVarianceIPFC(
//			pImageFilter->myClone(), &IPFE_Config.ShapePatternList_ForMeanAndVariance
//			)
//			);
//
//		delete pImageFilter;
//		pImageFilter = NULL;
//	}
//
//	CImagePositionFeatureExtractor* ret = new CBasicIPFE(pCompositeIPFC, IPFE_Config.ImageExtent);
//
//	return ret;
//}
//
//CImagePyramidPositionFeatureExtractor* C_IPPFE_Factory_HiDe::GenerateIPPFE(int CacheSize)
//{
//	CImagePositionFeatureExtractor* pIPFE = GenerateIPFE();
//	CImagePyramidPositionFeatureExtractor* ret = new CImagePyramidPositionFeatureExtractor(pIPFE, CacheSize);
//	return ret;
//}

